import { defineStore } from 'pinia'
import { ref } from 'vue'
import { EDITOR_STATE } from '@/constant/editor.state.js'

export const useEditorStore = defineStore('editor', () => {
  // 状态
  const mode = ref(EDITOR_STATE.PREVIEW)
  const isInputMode = ref(false)

  // 动作
  const setMode = (newMode) => {
    mode.value = newMode
  }

  const toggleMode = () => {
    if (mode.value === EDITOR_STATE.PREVIEW) {
      mode.value = EDITOR_STATE.DRAW_POINT
    } else {
      mode.value = EDITOR_STATE.PREVIEW
    }
  }

  const setDrawMode = (drawMode) => {
    if (mode.value !== EDITOR_STATE.PREVIEW) {
      mode.value = drawMode
    }
  }

  const setInputMode = (value) => {
    isInputMode.value = value
  }

  const toggleInputMode = () => {
    isInputMode.value = !isInputMode.value
  }

  return {
    // 状态
    mode,
    isInputMode,
    // 动作
    setMode,
    toggleMode,
    setDrawMode,
    setInputMode,
    toggleInputMode
  }
})
